/*
 * FileName：SouhuSelectedNewsJob.java 
 * <p>
 * Copyright (c) 2017-2020 <a href="https://www.smartwx.info">hermit(1154808491@qq.com)</a>.
 * <p>
 * Licensed under the GNU General Public License, Version 3 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/gpl-3.0.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.smart.webmagic.job;

import com.smart.webmagic.processor.SouhuProcessor;
import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.Spider;

import java.io.Serializable;

@Component
public class SouhuSelectedNewsJob implements Job,Serializable {

    private static final Logger logger = LoggerFactory.getLogger(SouhuSelectedNewsJob.class);
    @Autowired
    private SouhuProcessor souhuProcessor;
    /**
     * 每天早晨1點更新
     *
     * @author hermit
     * @date 2017 -08-08 18:17:31
     */
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //取得job详情
        JobDetail jobDetail = jobExecutionContext.getJobDetail();
        JobDataMap dataMap = jobDetail.getJobDataMap();
        logger.info("{} {}", dataMap.getString("title"),dataMap.getString("url"));
        Spider.create(souhuProcessor).addUrl("http://news.sohu.com/").thread(5).run();
    }
}
